package com.hucheng.activity.entity;

import com.hucheng.activity.dto.UserPointDetailsDTO;
import com.hucheng.activity.dto.UserPointExpiredDetailsDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-10
 * @Description: 持久层数据
 **/
@Data
public class UserPointExpiredDetailsDO {
    private Integer userPointExpiredDetailsId;
    private Integer point;
    private Integer userId;
    private Integer pointType;
    private String source;
    private Date expiredTime;
    private Integer isDel;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static UserPointExpiredDetailsDO buildUserPointExpiredDetailsDO(final UserPointExpiredDetailsDTO userPointExpiredDetailsDTO) {
        if (userPointExpiredDetailsDTO != null) {
            UserPointExpiredDetailsDO userPointExpiredDetailsDO = new UserPointExpiredDetailsDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(userPointExpiredDetailsDTO.getUserPointExpiredDetailsId()+"")) {
                userPointExpiredDetailsDO.setUserPointExpiredDetailsId(userPointExpiredDetailsDTO.getUserPointExpiredDetailsId());
                userPointExpiredDetailsDO.setDateCreated(currentTime);
            }else{
                userPointExpiredDetailsDO.setDateUpdated(currentTime);
            }
            userPointExpiredDetailsDO.setPoint(userPointExpiredDetailsDTO.getPoint());
            userPointExpiredDetailsDO.setUserId(userPointExpiredDetailsDTO.getUserId());
            userPointExpiredDetailsDO.setPointType(userPointExpiredDetailsDTO.getPointType());
            userPointExpiredDetailsDO.setSource(userPointExpiredDetailsDTO.getSource());
            userPointExpiredDetailsDO.setExpiredTime(userPointExpiredDetailsDTO.getExpiredTime());
            userPointExpiredDetailsDO.setIsDel(userPointExpiredDetailsDTO.getIsDel());
            return userPointExpiredDetailsDO;
        }
        return null;
    }
}
